package cn.com.yunhe.controller;

import cn.com.yunhe.bean.CCarChexing;
import cn.com.yunhe.service.CCarChexingService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CCarChexingController {
    /*
    * 车型的首页面
    * */
    @Resource
    private CCarChexingService ccarChexingService;
    @RequestMapping("/chexinglist")
    public String list(){
        return "houtai/chexing";
    }
    /*
    * 在首页面获取全部车型得到json数据
    * */
    @RequestMapping("/allchexing")
    @ResponseBody
   public List<CCarChexing> allchexing(CCarChexing cCarChexing){
        System.out.println("查询条件"+cCarChexing);
        Map map = new HashMap();
        map.put("cCarChexing",cCarChexing);

        return ccarChexingService.querychexing(map);
    }
    /*
    * 进入新增车型页面
    * */
    @RequestMapping("/addchexingtem")
    public String addchexingtem(){
        return "houtai/addchexing";
    }
   /*
   * 处理新增车型
   * */
   @RequestMapping("/addchexing")
   public String addchexing(CCarChexing cCarChexing){
       //System.out.println(cCarChexing);
       int i;
       i = ccarChexingService.addChexing(cCarChexing);
       if (i>0){
           return "houtai/chexing";
       }else{
           return "houtai/addchexing";
       }
   }
   /*
   * 进入修改车型的页面
   * */
   @RequestMapping("/updatechexingtem")
    public ModelAndView updatechexingtem(String id){
       System.out.println("接收的id是："+id);
       CCarChexing cCarChexing = ccarChexingService.queryOneChexing(Integer.parseInt(id));
       ModelMap map = new ModelMap();
       map.addAttribute("OneChexing",cCarChexing);
       System.out.println(cCarChexing);
       return new ModelAndView("houtai/updatechexing",map);
    }
    /*
    * 处理修改车型
    * */
    @RequestMapping("/updatechexing")
    public String updatechexing(CCarChexing cCarChexing){
        Integer integer = ccarChexingService.uptChexing(cCarChexing);
        if (integer>0){
            return "houtai/chexing";
        }else{
            return "houtai/updatechexing";
        }
    }
    /*
    * 删除某一具体的车型
    * */
    @RequestMapping("/delchexing")
    @ResponseBody
    public Boolean delChexing(String id){
        Boolean bool;
        Integer integer = ccarChexingService.delChexing(Integer.parseInt(id));
        if (integer>0){
            return bool = true;
        }else{
            return bool = false;
        }
    }
}
